<?php
     require_once('../configs/common.php'); 	 
	 require_once("../configs/db_connect.php");
	 
if ($_POST['action']=="get_all_country")
{
	 $countries=SQL::select(Template::render("getAllCountry.sql", "sql", array()));
	 
	 header('Content-Type: application/json');
	 echo json_encode($countries);

}

if ($_POST['action']=="get_regions")
{
	 $country=safe_var_Array(json_decode($_POST['data']), true);
	 if (!is_numeric($country['id']))
	 {
		 return;
	 } 
	 
	 $regions=SQL::select(Template::render("getRegionByCountryID.sql", "sql", array('id_country'=>$country['id'])));
	 
	 header('Content-Type: application/json');
	 echo json_encode($regions);

}

if ($_POST['action']=="get_cities")
{
	 $data=safe_var_Array(json_decode($_POST['data']), true);
	 if (!is_numeric($data['contry_id'])||!is_numeric($data['region_id']))
	 {
		 return;
	 } 
	 
	 $cities=SQL::select(Template::render("getCities.sql", "sql", array('id_country'=>$data['contry_id'],'id_region'=>$data['region_id'])));
	 
	 header('Content-Type: application/json');
	 echo json_encode($cities);

}